﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using System.Web.Mvc;

using Microsoft.Practices.Unity;

using ERPStore.Extensions;

using EventBrokR;

namespace ERPStore.Localization
{
	public class PluginInit : ERPStore.Extensibility.PluginInit
	{
		public PluginInit()
		{
			Container = GlobalConfiguration.Configuration.DependencyResolver.GetContainer();
		}

		Microsoft.Practices.Unity.IUnityContainer Container { get; set; }

		public override void AddServices()
		{
			Container.RegisterType<Repositories.ILocalizationRepository, Repositories.VoidLocalizationRepository>();
			Container.RegisterType<ERPStore.Services.ILocalizationService, Services.LocalizationService>(new ContainerControlledLifetimeManager());

			var eb = Container.Resolve<EventBrokR.IPublisher>();
			// Enregistrement de l'evenement "Routes enregistrées"
			eb.Container.Register<EventConsumers.RegisteredRoutesEventMessage>();
		}

		public override void RegisterRoutes()
		{
			base.RegisterRoutes();

			var namespaces = new string[] { "ERPStore.Localization.Controllers" };

			RouteTable.Routes.MapRoute(
				"LocalizeDefault"
				, "localize/{action}/{id}"
				, new { controller = "Localization", action = "Index", Id = string.Empty }
				, namespaces
			);
		}

	}
}
